package com.siao.applications
{
	import com.siao.mvc.core.IState;
	
	import flash.display.DisplayObject;
	
	/**
	 * 单例模块，在同一应用程序中只允许存在一个单例模块，添加新的单例模块会移除之前添加的其他单例模块
	 * @author SiaoLeon
	 */
	public class SingleModule extends Module
	{
		// -------------------------------------------------------------------------------------------------------- 静态常量
		
		// -------------------------------------------------------------------------------------------------------- 静态变量
		
		// -------------------------------------------------------------------------------------------------------- 静态方法
		
		// -------------------------------------------------------------------------------------------------------- 静态函数
		
		// -------------------------------------------------------------------------------------------------------- 属性
		
		// -------------------------------------------------------------------------------------------------------- 变量
		
		// -------------------------------------------------------------------------------------------------------- 构造
		
		/**
		 * 构造函数
		 */
		public function SingleModule(root:IState=null)
		{
			super(root);
		}
		
		// -------------------------------------------------------------------------------------------------------- 方法
		
		override protected function onAddedToStage():void
		{
			super.onAddedToStage();
			
			if (this.parent == null)
			{
				return;
			}
			
			for (var i:int = this.parent.numChildren - 1; i >= 0; i--)
			{
				var child:DisplayObject = this.parent.getChildAt(i);
				
				if (child == this)
				{
					continue;
				}
				
				if (child is SingleModule)
				{
					(child as SingleModule).remove();
				}
			}
		}
	
		// -------------------------------------------------------------------------------------------------------- 函数
	
	}
}
